#ifndef CONSOLE_H
#define CONSOLE_H
#include <windows.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <cstdlib>

enum {
	SC_BLACK = 0,
	SC_BLUE = 1,
	SC_GREEN = 2,
	SC_LBLUE = 3,
	SC_RED = 4,
	SC_PURPLE = 5,
	SC_YELLOW = 6,
	SC_WHITE = 7,
	SC_GRAY = 8,
	SC_LIGHTBLUE = 9,
	SC_LIGHTGREEN = 0xA,
	SC_LLIGHTGREEN = 0xB,
	SC_LIGHTRED = 0xC,
	SC_LIGHTPURPLE = 0xD,
	SC_LIGHTYELLOW = 0xE,
	SC_HIGHTWHITE = 0xF
};

class Console {

public:
	explicit Console(): nProgressLength(0),hSTDHANDLE(NULL),cProgressFlag('='),cProgressFlagLess(' '),bProgressInit(false){
		hSTDHANDLE = GetStdHandle(STD_OUTPUT_HANDLE);
	}
	~Console(){
		CloseHandle(hSTDHANDLE);
	} 
	
	COORD Getxy(void) const;//
	
	void ClearScr(void) const;//
	void InitProgress(void);//
	void SetProgressStyle(char cFlag,char cFlagLess = ' ');//
	void ShowProgress(void) const;//
	void ShowProgress(int nPos,int nSplit);//
	void DeleteProgress(void) const;//
	
	long SetGlobalColor(short sForeg,short sBackg) const;//
	/*	Foreground and background color use the same code:
		0=???	1=???	2=???	3=?????	4=???		5=???
		6=???	7=???	8=???	9=?????	A=?????	B=??????
		C=?????	D=?????	E=?????	F=?????
	*/
	bool SetColor(WORD wForegColor,WORD wBackgColor);//
	/*	The text printed after this function was calling has new fgd and bgd color
		wForegColor:FOREGROUND_BLUE j??????
					FOREGROUND_GREEN j??????
					FOREGROUND_RED j??????
					FOREGROUND_INTENSITY j???????
		wBackgColor:BACKGROUND_BLUE ????????
					BACKGROUND_GREEN ????????
					BACKGROUND_RED ????????
					BACKGROUND_INTENSITY ?????????	
	*/
	bool SetTitle(std::string& strTitle);//
	bool Gotoxy(short x,short y) const;//
	
	std::string GetTitle(void) const;//

protected:
	void SetProgress(int nPos,int nSplit);//
	
private:
	HANDLE hSTDHANDLE;
	
	int nProgressLength;
	char cProgressFlag,cProgressFlagLess;
	bool bProgressInit;
	std::string strProgress;
};

#endif